home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk75 / ispell / src / term.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-19  |  2.9 KB  |  172 lines

  1. /* -*- Mode:Text -*- */
  2. /*
  3.  * term.c - deal with termcap, and unix terminal mode settings
  4.  *
  5.  * Pace Willisson, 1983
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <sgtty.h>
  10. #include <signal.h>
  11. #include "ispell.h"
  12.  
  13. int putch();
  14.  
  15. erase ()
  16. {
  17.     if (cl)
  18.         tputs(cl, li, putch);
  19.     else {
  20.         if (ho)
  21.             tputs(ho, 100, putch);
  22.         else if (cm)
  23.             tputs(tgoto(cm, 0, 0), 100, putch);
  24.         tputs(cd, li, putch);
  25.     }
  26. }
  27.  
  28. move (row, col)
  29. {
  30.     tputs (tgoto (cm, col, row), 100, putch);
  31. }
  32.  
  33. inverse ()
  34. {
  35.     tputs (so, 10, putch);
  36. }
  37.  
  38. normal ()
  39. {
  40.     tputs (se, 10, putch);
  41. }
  42.  
  43. backup ()
  44. {
  45.     if (BC)
  46.         tputs (BC, 1, putch);
  47.     else
  48.         putchar ('\b');
  49. }
  50.  
  51. putch (c)
  52. {
  53.     putchar (c);
  54. }
  55.  
  56. struct sgttyb sbuf, osbuf;
  57. static termchanged = 0;
  58.  
  59.  
  60. terminit ()
  61. {
  62.     int done();
  63.     short tpgrp;
  64.     int onstop();
  65.  
  66. retry:
  67.     sigsetmask(1<<SIGTSTP | 1<<SIGTTIN | 1<<SIGTTOU);
  68.     if (ioctl(0, TIOCGPGRP, &tpgrp) != 0) {
  69.         fprintf (stderr, "Can't deal with non interactive use yet.\n");
  70.         exit (1);
  71.     }
  72.     if (tpgrp != getpgrp(0)) { /* not in foreground */
  73.         sigsetmask(1<<SIGTSTP | 1<<SIGTTIN);
  74.         signal(SIGTTOU, SIG_DFL);
  75.         kill(0, SIGTTOU);
  76.         /* job stops here waiting for SIGCONT */
  77.         goto retry;
  78.     }
  79.  
  80.     ioctl (0, TIOCGETP, &osbuf);
  81.     termchanged = 1;
  82.  
  83.     sbuf = osbuf;
  84.     sbuf.sg_flags &= ~ECHO;
  85.     sbuf.sg_flags |= RAW;
  86.     ioctl (0, TIOCSETP, &sbuf);
  87.  
  88.     erasechar = sbuf.sg_erase;
  89.     killchar = sbuf.sg_kill;
  90.  
  91.     signal (SIGINT, done);
  92.  
  93.     sigsetmask(0);
  94.     signal(SIGTTIN, onstop);
  95.     signal(SIGTTOU, onstop);
  96.     signal(SIGTSTP, onstop);
  97.  
  98.     tgetent(termcap, getenv("TERM"));
  99.     termptr = termstr;
  100.     bs = tgetflag("bs");
  101.     BC = tgetstr("bc", &termptr);
  102.     UP = tgetstr("up", &termptr);
  103.     cd = tgetstr("cd", &termptr);
  104.     ce = tgetstr("ce", &termptr);    
  105.     cl = tgetstr("cl", &termptr);
  106.     cm = tgetstr("cm", &termptr);
  107.     dc = tgetstr("dc", &termptr);
  108.     dl = tgetstr("dl", &termptr);
  109.     dm = tgetstr("dm", &termptr);
  110.     ed = tgetstr("ed", &termptr);
  111.     ei = tgetstr("ei", &termptr);
  112.     ho = tgetstr("ho", &termptr);
  113.     ic = tgetstr("ic", &termptr);
  114.     il = tgetstr("al", &termptr);
  115.     im = tgetstr("im", &termptr);
  116.     ip = tgetstr("ip", &termptr);
  117.     nd = tgetstr("nd", &termptr);
  118.     vb = tgetstr("vb", &termptr);
  119.     so = tgetstr("so", &termptr);    /* inverse video on */
  120.     se = tgetstr("se", &termptr);    /* inverse video off */
  121.     co = tgetnum("co");
  122.     li = tgetnum("li");    
  123.  
  124. }
  125.  
  126. done ()
  127. {
  128.     unlink (tempfile);
  129.     if (termchanged)
  130.         ioctl (0, TIOCSETP, &osbuf);
  131.     exit (0);
  132. }
  133.  
  134. onstop(signo)
  135. int signo;
  136. {
  137.     ioctl (0, TIOCSETP, &osbuf);
  138.     signal(signo, SIG_DFL);
  139.     kill(0, signo);
  140.     /* stop here until continued */
  141.     signal(signo, onstop);
  142.     ioctl (0, TIOCSETP, &sbuf);
  143. }
  144.  
  145. stop ()
  146. {
  147.     onstop (SIGTSTP);
  148. }
  149.  
  150. shellescape (buf)
  151. char *buf;
  152. {
  153.     ioctl (0, TIOCSETP, &osbuf);
  154.     signal (SIGINT, 1);
  155.     signal (SIGQUIT, 1);
  156.     signal(SIGTTIN, SIG_DFL);
  157.     signal(SIGTTOU, SIG_DFL);
  158.     signal(SIGTSTP, SIG_DFL);
  159.  
  160.     system (buf);
  161.  
  162.     signal(SIGTTIN, onstop);
  163.     signal(SIGTTOU, onstop);
  164.     signal(SIGTSTP, onstop);
  165.     signal (SIGINT, done);
  166.     signal (SIGQUIT, SIG_DFL);
  167.  
  168.     ioctl (0, TIOCSETP, &sbuf);
  169.     printf ("\n-- Type space to continue --");
  170.     getchar ();
  171. }
  172.